﻿using StackExchange.Redis;
using System;
using System.Collections.Generic;
using XCore.Redis;
using XCore.Extensions;
using XCore.Dependency;

namespace SaaS.Cache.Logs
{
    public class LoggerCacheService : CacheServiceBase, ISingletonDependency
    {
        protected override int Db => 5;
        public IEnumerable<T> GetLogs<T>(string key)
        {
            while (true)
            {
                RedisValue value = this.Redis.ListRightPop(key);
                if (value.IsNullOrEmpty) break;
                var stringJson = value.GetRedisValue<string>();
                yield return stringJson.ToObject<T>();
            }
        }
    }
}
